﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace SVAccountingBL
{
    [DataObject(true)]
    public class BatchODS
    {
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static List<BatchTemplateClass> GetAccountantBatches(int accountantID)
        {
            List<BatchTemplateClass> theBatches = new List<BatchTemplateClass>();
            BatchTemplateClass btcObj = new BatchTemplateClass();

            SVALinqDataContext db = new SVALinqDataContext();

            var result = from p in db.Batches where p.CompanyAccountantID == accountantID
                         select p;

            foreach (var item in result)
            {
                btcObj.BatchID = item.BatchID;
                btcObj.CreationDate = item.CreationDate;
                btcObj.CompanyAccountantID = item.CompanyAccountantID;
                btcObj.isOpend = item.IsOpened;
                btcObj.isValid = item.IsValid;

                var tTransaction = from t in db.Transactions
                                   where t.BatchID == item.BatchID
                                   select t;

                btcObj.BatchTransactions = tTransaction.ToList();
            }



            return theBatches;
        }
    }


    public class BatchTemplateClass
    {
        public int BatchID { get; set; }
        public DateTime CreationDate { get; set; }
        public int CompanyAccountantID { get; set; }
        public bool isOpend { get; set; }
        public bool isValid { get; set; }

        public List<Transaction> BatchTransactions { get; set; }

        public BatchTemplateClass() { }
    }
    
}
